var net    = require('net'),
    puerto = 1337,
    ack    = 'x';
	
var server = net.createServer(function (socket) {
  var remoteAddress	= socket.remoteAddress;
  var remotePort = socket.remotePort;

  console.log('----------------------------------------------------------------------');
  console.log('sock :: connect ' + remoteAddress + ':' + remotePort + ' cons_activas=' + server.connections);
  console.log(new Date());
  
  socket.on('data', function (data) {
	socket.write(ack); // <- un ack
	console.log(data.toString('utf-8'));
  });
  
  socket.on('close', function () {
	console.log('sock :: close');
  });
  
  socket.on('error', function () {
	console.log('sock :: error');
	socket.destroy();
  });
});

server.on('listening', function () {
	console.log('servidor escuchando en puerto %d', puerto);
	console.log((new Date()).toString());
});

server.on('error', function (err) {
	// ... tratamiento de errores aca
});

server.listen(puerto);
